<?php
if(!defined('BZ_XTBLOG') || !defined('BZ_WJSCUZ')) {
	exit('Access Denied');
}
$wzxx_title ='帖子回复-'.$wzxx_title.'';
$wzxx_gj    ='帖子回复-'.$wzxx_gj.'';
$wzxx_ms    ='帖子回复-'.$wzxx_ms.'';
$act=$_GET['act'];
$fid =verify_id($_GET['fid']);
$tid =verify_id($_GET['tid']);
$forum=$db->get_one('forum'," `id` ='$fid' AND `sz_sc` ='0'",'');
$forumsjpd  =$db->get_one('forum_hui'," `uid` ='$user_uid' ORDER BY `id` DESC LIMIT 0,1",'');
$forumsjpdz =$db->get_one('forum_hui'," `uid` ='$user_uid' AND `fid` ='$forum[id]' AND `time_a` > ".$time_jt." ",'');
$forumsjpdz2=$db->get_one('forum_hui'," `uid` ='$user_uid' AND `fid` ='$forum[id]' AND `time_a` > ".$time_jt-(7*24*3600)." ",'');
$forumsjpdz3=$db->get_one('forum_hui'," `uid` ='$user_uid' AND `fid` ='$forum[id]' AND `time_a` > ".$time_jt-(30*24*3600)." ",'');

if(!$user_uid){
		$pdid='2';
	}else if(!$forum){
		$pdid='1';
	}else if($act == 'top'){
       if(!$db->get_one('forum_polloption'," `tid` ='$fid'",'')){
		      $mmts='你好，投票数据出错！';
       }elseif($forum[type] !='1'){
  	      $pdid='3';
		      $mmts='你好，帖子出错！';
       }elseif($forum[type_tp_gb] =='1'){
		      $mmts='你好，投票已经结束！';
       }elseif($db->get_one('forum_polloption_user'," `tid` ='$fid' AND `uid` ='$user_uid' ",'')){
		      $mmts='你好，你已投票！';
       }else{
       	  $db->insert('forum_polloption_user',array('id' => 'NULL','tid' => $fid,'tpid' => $tid,'uid' => $user_uid));	
		      $mmts='你好，投票成功！';
		   }
		   $pdid='6';
	}else if($act == 'ok'){
       $content  =$_POST[content];
       if(empty($content)){
  	      $pdid='3';
		      $mmts='你好，不能为空！';
       }elseif($forum[type_suo] =='1'){
  	      $pdid='3';
		      $mmts='你好，不能回复！';
       }elseif($forumsjpd[content] == $content){
  	      $pdid='3';
		      $mmts='你好，禁止重复提交！';
       }else{
           if(preg_match("/\[huifu=(.*?)\]/s",$content,$daima)){
           	  $contmt=explode("/",$daima[1]);
           	  $foidm=$db->get_one('forum_hui'," `id` ='$contmt[1]'",'uid');
           	  Bingz_message_post('0',$foidm[uid],'你好！你在帖子【[url=index.php?'.$Bingz_ml.'=forum&'.$Bingz_md.'=viewthread&fid='.$forum[id].']'.$forum[name].'[/url]】[b]'.$contmt[0].'[/b]评论有了回复！快去查看吧！');
    	        $content=str_replace($daima[0],'',$content);
           }
           if($_FILES['upfile']['name']){
              $mmurl=date("Y/m/d/");
              $bzwjc=Bingz_upload('forum/'.$mmurl,'0','2');
              if($bzwjc[1] == '1'){
          	  if(in_array($bzwjc[4], array('jpg','jpeg','png','gif'))) {$fjlx='1';}else{$fjlx='2';}
              if($db->insert('forum_data','`id`, `uid`,`fid`, `money`, `url`, `name`, `fjgs`, `fjlx`, `size`, `time_a`',"NULL ,  '$user_uid', '$forum[id]','$_POST[money]' , '$mmurl$bzwjc[2]', '$bzwjc[5]', '$fjlx', '$bzwjc[4]', '$bzwjc[3]', '$time'")){
                $id=$db->insert_id();
                $tjts="上传成功<br/>";
              }else{
		            $tjts="上传失败<br/>";
              }
    	        }else{
		            $tjts="上传失败<br/>上传附件：".$bzwjc[2]."<br/>";
              }
              $content=$content.'[attach]'.$id.'[/attach]';
           }
           if(Bingz_forum_hui_post($forum[id],$user_uid,$content,$contmt[1],$contmt[0])){
              if($forum[uid] != $user_uid && $forum[sz_tz] == '1'){
	           	  Bingz_message_post('0',$forum[uid],'你好！你的帖子【[url=index.php?'.$Bingz_ml.'=forum&'.$Bingz_md.'=viewthread&fid='.$forum[id].']'.$forum[name].'[/url]】有了新的评论！快去查看吧！');
	            }
              
     if(preg_match_all("/@(.*?)(?:[,| ])/",$content,$smsoon)){
        $smsoon[1]=array_unique($smsoon[1]);
        foreach( $smsoon[1] as $a=> $val){
                if($nnmm=$db->get_one('user'," `name` = '$val' ",'uid')){
                	 	  $db->insert('message',array('id' => 'NULL', 'fo_id' => 0, 'to_id' => $nnmm[uid], 'content' => "帖子《[url=index.php?$Bingz_ml=forum&$Bingz_md=viewthread&fid=$forum[id]]$forum[name][/url]》回复中@我了！", 'time_a'=> $time ));
                }
        }
     }
              
              
              $pdid='4';
    	     }else{
		          $pdid='5';
           }
       }
	}
@include template('head');
@include template('forum/forum_viewthreadpost');
@include template('foot');
?>